#ifndef TD_ENTRY_SCREEN_H_
#define TD_ENTRY_SCREEN_H_

/************************************************************************/
/* STL                                                                  */
/************************************************************************/
#include <deque>

/************************************************************************/
/* CORE                                                                 */
/************************************************************************/
#include "Core/Timer.h"
#include "Core/Utils.h"

/************************************************************************/
/* GUI                                                                  */
/************************************************************************/
#include "GUI/Panels/BasePanel.h"
#include "GUI/Bars/ProgressBar.h"
#include "GUI/Misc/Fadescreen.h"
#include "GUI/Textmessages/FadingMessage.h"

/************************************************************************/
/* Resources                                                            */
/************************************************************************/
#include "Resources/ResourceManager.h"
#include "Game/Animations/StandardAnimationSet.h"
#include "Resources/Tiles/Tile.h"


using namespace std;
using namespace boost;

namespace TD_Core {

	class EntryScreen : public BasePanel {

		typedef enum {
			atLogo,
			atMain,
			atCredits,
			atIntro,
			invalidArea
		} entryScreenArea;

		typedef enum {
			//Scene 1
			bowserWaiting,
			bowserTalking,
			bowserTalking2,
			bowserTalking3,
			sceneFadingOut,
			sceneFadingIn,
			
			//Scene 2
			bowserTalking4,
			magikoopaTalking,
			magikoopaTalking2,
			magikoopaTalking3,
			sceneFadingOut2,
			sceneFadingIn2,

			//Scene 3
			bowserTalking5,
			snifitTalking,
			snifitTalking2,
			sceneFadingOut3,
			sceneFadingIn3,
			
			//Scene 4
			bowserTalking6,
			shyguyTalking,
			shyguyTalking2,
			shyguyTalking3,
			shyguyTalking4,
			shyguyTalking5,
			sceneFadingOut4,
			sceneFadingIn4,

			//Scene 5
			bowserTalking7,
			lakituTalking,
			lakituTalking2,
			lakituTalking3,
			lakituTalking4,
			sceneFadingOut5,

			//
			introFinal,
			introFinal2,
			introFinal3,
			introFinal4, 
			introFinal5,
			introFinal6,
			introFinal7,
			introFinal8,

			introFinalFinal
		} introSubArea;

		/************************************************************************/
		/* Default definitions                                                  */
		/************************************************************************/
		static const string entryScreenBackground;
		static const Coord2D iconStartingPos;

		Fadescreen *m_pFadescreen;
		entryScreenArea m_currArea;
		entryScreenArea m_nextArea;
		int m_difficultSelected;

		/** Logo Variables:*/
		Tile *m_pLacaLogo;
		shared_ptr<SDLSound> m_pLogoSound;
		bool m_playedIntroSound;
		Timer m_logoTimer;

		/** Main area Variables:*/
		Tile *m_pBowserIcon;
		bool m_advanceToGame;
		unsigned char m_bowserIndex;

		/** Credits Variables:*/
		Tile *m_pRoscaCredits;
		Tile *m_pBassCredits;
		Tile *m_pBebeCredits;
		Tile *m_pGottinCredits;
		Timer m_creditsTimer;

		/************************************************************************/
		/* INTRO                                                                */
		/************************************************************************/

		Tile *m_pIntroBackground;

		/**AS*/
		
		Coord2D m_bowserPosition;
		AnimationSet *m_bowserAnimationSet;
		Coord2D m_magikoopaPosition;
		AnimationSet *m_pMagikoopaAnimationSet;
		Coord2D m_snifitPosition;
		AnimationSet *m_pSnifitAnimationSet;
		Coord2D m_shyguyPosition;
		AnimationSet *m_pShyguyAnimationSet;
		Coord2D m_lakituPosition;
		AnimationSet *m_pLakituAnimationSet;
		

		FadingMessage *m_pFadingMessage;
		introSubArea m_introSubArea;
		introSubArea m_lastSubArea;
		shared_ptr<SDLSound> m_pBowserSound;
		shared_ptr<SDLMusic> m_pIntroMusic;
		Timer m_introTimer;

		/** SFX*/
		shared_ptr<SDLSound> m_pFireSound;

		void update(unsigned int deltaTime);

		void processLogo(SDL_Surface *g_pSurface, unsigned int deltaTime);
		void processMain(SDL_Surface *g_pSurface, unsigned int deltaTime);
		void processCredits(SDL_Surface *g_pSurface, unsigned int deltaTime);
		void processIntro(SDL_Surface *g_pSurface, unsigned int deltaTime);
		inline void setIntroText(const string &introText) {
			m_pFadingMessage->resetFading();
			m_pFadingMessage->setPosition(Coord2D(screenWidth/2 - introText.size()*7.5, 600));
			m_pFadingMessage->setText(introText);
		}
		void processIntroSubArea();


		interaction_t processKeyboardLogo(const SDL_Event  & event);
		interaction_t processKeyboardMain(const SDL_Event  & event);
		interaction_t processKeyboardCredits(const SDL_Event  & event);
		interaction_t processKeyboardIntro(const SDL_Event &event);
		interaction_t processKeyboard(const SDL_Event  & event);

		interaction_t processMouse(const SDL_Event &event);

		void moveUpBowserIcon();
		void moveDownBowserIcon();

	public:


		/************************************************************************/
		/* ctors and dtors					                                    */
		/************************************************************************/
		//Default constructor
		explicit EntryScreen();

		//Copy constructor
		explicit EntryScreen(const EntryScreen &rhs);

		//Assignment constructor
		EntryScreen& operator=(const EntryScreen &rhs);

		//Destructor
		~EntryScreen();

		/************************************************************************/
		/* Rendering                                                            */
		/************************************************************************/


		void render(SDL_Surface *const g_destSurface, unsigned int deltaTime);

		interaction_t processEvent(const SDL_Event &event);

		inline bool isFinished() const {
			return m_pFadescreen->isFadingOut() && m_pFadescreen->finishedFading();
		}
	};
}


#endif